<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>权限管理</title>
    <jsp:include page="../../../../head.jsp"/>
</head>
<script type="text/javascript">
    var id = '${id}';
    var mid = '${module.id}';
    var title = "添加";
    if (id) {
        title = "修改";
    }
    title += "权限";
    var useState = $.mrdForm.ajaxdp("dropdown-useState");
    var hideState = $.mrdForm.ajaxdp("dropdown-hiddenState");
    var pmsType = $.mrdForm.ajaxdp("dropdown-pmsType");
    var formSetting = {
        title: title,
        module: "save",
        numCount: 1,
        columns: [{
            name: "id",
            hidden: true
        }, {
            name: "name",
            label: "权限名称",
            validate: 'validate[required]'
        }, {
            name: "pid",
            label: "权限标识",
            validate: 'validate[required]'
        }, {
            name: "type",
            label: "权限类型",
            type: "dropdown",
            data: pmsType,
            validate: 'validate[required]'
        }, {
            name: "disable",
            label: "启用状态",
            type: "dropdown",
            data: useState,
            value: "0",
            dropdownValue: "启用"
        }, {
            name: "buttonId",
            label: "按钮id"
        }, {
            name: "label",
            label: "按钮显示值"
        }, {
            name: "click",
            label: "触发事件"
        }, {
            name: "hidden",
            label: "隐藏状态",
            type: "dropdown",
            data: hideState
        }, {
            name: "module.id",
            hidden: true,
            value: mid
        }],
        buttons: {
            custom: []
        },
        form: {
            url: "mod-perSave",
            'data': function () {
                if (id) {
                    var dataValue = "";
                    $
                            .ajax({
                                      url: "mod-perBeUpdate?id=" + id,
                                      async: false,
                                      success: function (data) {
                                          if (data.permissions != null) {
                                              var dropdownName = $.mrdForm
                                                      .getDropDwonLabelName("disable");
                                              data[dropdownName] = $.mrdForm
                                                      .dropdownShowValue(useState,
                                                                         data.disable);
                                              dropdownName = $.mrdForm
                                                      .getDropDwonLabelName("hidden");
                                              data[dropdownName] = $.mrdForm
                                                      .dropdownShowValue(hideState,
                                                                         data.hidden);
                                              dropdownName = $.mrdForm
                                                      .getDropDwonLabelName("type");
                                              data[dropdownName] = $.mrdForm
                                                      .dropdownShowValue(pmsType,
                                                                         data.type);
                                          }
                                          dataValue = data;
                                      }
                                  });
                    return dataValue;
                } else {
                    return null;
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                var msg = $.parseJSON(responseText.msg);
                if (msg.state == "1") {
                    window.parent.refresh();
                    jw.close();
                }
            }
        }
    };
    $(document).ready(function () {
        $("#persave").mrdForm(formSetting);
    });
</script>
<body>
<div id="persave"></div>
</body>
</html>
